Strict

Import agfx

Global myTmpScreen:TTmpScreen

Class TAgfx_test_app Extends TFramework

	Method OnCreate:Int()
		
		Super.OnCreate()
				
		myTmpScreen = New TTmpScreen		
		myTmpScreen.Prepare()
		
		Return 0
	End
	
End


Class TTmpScreen Extends TScreen
	
	Field point:TPoint
	Field line:TLine
	Field triangle:TTriangle
	Field rectangle:TRectangle
	Field polyline:TPolyline
	Field polygon:TPolygon
	Field ngon:TNgon
	
	Field primitives:ArrayList<TPrimitive> = New ArrayList<TPrimitive>()
	
	Field a:Float=0
	' START when app is created
	Method Start:Void()
	
		' CREATE POINT
		Self.point = New TPoint()
		Self.point.Create(New TVector2(50,50))		
		
		
		Self.primitives.Add(Self.point)
	
		' CREATE LINE
		Self.line = New TLine()
		Self.line.Create(New TVector2(0,50),New TVector2(100,50))
		Self.line.SetOffset(100,50)
		
		
		Self.primitives.Add(Self.line)
		
		' CREATE TRIANGLE
		Self.triangle = New TTriangle()
		Self.triangle.Create(New TVector2(-25,0),New TVector2(0,50),New TVector2(25,0))		
		Self.triangle.SetOffset(100,150)
		
		
		Self.primitives.Add(Self.triangle)
		
		' CREATE RECTANGLE
		Self.rectangle = New TRectangle()
		
		Self.rectangle.Create(New TVector2(0,0),New TVector2(128,0),New TVector2(128,24),New TVector2(0,24))
		Self.rectangle.SetOffset(200,150)
		
'		Self.rectangle.AddPoint(New TVector2(0,0))
'		Self.rectangle.AddPoint(New TVector2(128,0))
'		Self.rectangle.AddPoint(New TVector2(128,24))
'		Self.rectangle.AddPoint(New TVector2(0,24))
'		Self.rectangle.Build()		
'		Self.rectangle.SetOffset(200,150)
		
		Self.primitives.Add(Self.rectangle)
		
		' Create POLYGON
		Self.polygon = New TPolygon()
		
		Self.polygon.AddPoint(New TVector2(30,30))
		Self.polygon.AddPoint(New TVector2(50,10))
		Self.polygon.AddPoint(New TVector2(60,30))
		Self.polygon.AddPoint(New TVector2(50,60))
		Self.polygon.AddPoint(New TVector2(40,60))
		Self.polygon.SetOffset(480,60)
		
		Self.primitives.Add(Self.polygon)
		
		
		' Create POLYGON
		Self.polyline = New TPolyline()
		
		Self.polyline.AddPoint(New TVector2(30,30))
		Self.polyline.AddPoint(New TVector2(50,10))
		Self.polyline.AddPoint(New TVector2(60,30))
		Self.polyline.AddPoint(New TVector2(50,60))
		Self.polyline.AddPoint(New TVector2(40,60))
		Self.polyline.SetOffset(480,360)
		
		Self.primitives.Add(Self.polyline)
		
		' Create 8-gon
		Self.ngon = New TNgon()
		Self.ngon.Create(New TVector2(300,300),64,8)
		
		Self.primitives.Add(Self.ngon)
		
		Print(Self.polygon.edges.Size())
		Self.polygon.CalcEdges()
		Print(Self.polygon.edges.Size())
		
		For Local e:TEdge = EachIn Self.polygon.edges
			Print("A:"+e.A.ToString())
			Print("B:"+e.B.ToString())
		Next
		
		
	End
	
	' main app logic loop update
	Method Update:Void()
		
		For Local pol:TPrimitive = EachIn Self.primitives
			'pol.Draw()
			pol.Update()
		Next
		
		a += 0.125
	
		If KeyDown(KEY_UP) Then Self.polygon.SetOffset(0,-1)
		If KeyDown(KEY_DOWN) Then Self.polygon.SetOffset(0,1)
		If KeyDown(KEY_LEFT) Then Self.polygon.SetOffset(-1,0)
		If KeyDown(KEY_RIGHT) Then Self.polygon.SetOffset(1,0)
		
		' rotate around point from polygon
		
		Self.polygon.Rotate(2)
		Self.rectangle.Rotate(2)
		Self.line.RotateByID(1,2)
		Self.triangle.RotateAt(New TVector2(100,100),-2)
		
		
		Self.ngon.SetOffset(Sinr(a)*0.5,Sinr(a)*0.5)
		Self.polygon.SetOffset(0,Sinr(a)*0.5)
		Self.rectangle.SetOffset(0,Sinr(a)*0.5)
		Self.line.SetOffset(0,Sinr(a)*0.5)
		Self.triangle.SetOffset(Sinr(a)*0.5,0)
		Self.polyline.SetOffset(Sinr(a)*0.5,0)
		
		' rotate around calculated center
		'Self.polygon.Rotate(2)
		
	End
	
	' main app render loop
	Method Render:Void()
		Cls
		For Local pol:TPrimitive = EachIn Self.primitives
			'pol.Draw()
			pol.DrawDebug()
		Next
	End
End
